package qlsl.androiddesign.adapter.subadapter;

import java.util.List;

import com.qlsl.androiddesign.kuaiwa.R;

import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import qlsl.androiddesign.activity.baseactivity.BaseActivity;
import qlsl.androiddesign.activity.subactivity.PostingDetailActivity;
import qlsl.androiddesign.adapter.baseadapter.BaseAdapter;
import qlsl.androiddesign.entity.otherentity.Posting;
import qlsl.androiddesign.util.commonutil.ImageUtils;
import qlsl.androiddesign.util.commonutil.TimeFormatUtils;

/**
 * 帖子一级分类列表<br/>
 */
public class PostingCategoryAdapter extends BaseAdapter<Posting> {

	public PostingCategoryAdapter(BaseActivity activity, List<Posting> list) {
		super(activity, list);
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		convertView = getItemView(convertView,
				R.layout.listitem_posting_category);

		ImageView iv_icon = getView(convertView, R.id.iv_icon);
		TextView tv_name = getView(convertView, R.id.tv_name);
		TextView tv_time = getView(convertView, R.id.tv_time);
		TextView tv_section = getView(convertView, R.id.tv_section);
		TextView tv_sec_title = getView(convertView, R.id.tv_sec_title);
		TextView tv_num_view = getView(convertView, R.id.tv_num_view);
		TextView tv_num_comment = getView(convertView, R.id.tv_num_comment);

		final Posting item = getItem(position);

		ImageUtils.circle(activity, item.getHeadphoto(), iv_icon);
		tv_name.setText(item.getUsername());
		tv_time.setText(TimeFormatUtils.format(item.getTime()));
		tv_section.setText("[" + item.getFirstsection() + ">"
				+ item.getSecondsection() + "]");
		tv_sec_title.setText(item.getPostingsname());
		tv_num_view.setText("浏览" + item.getViews());
		tv_num_comment.setText("评论" + item.getComment());

		convertView.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				Intent intent = new Intent(activity,
						PostingDetailActivity.class);
				intent.putExtra("data", item);
				activity.startActivityForResult(intent, 0);
			}
		});

		return convertView;
	}
}
